package pl.com.qapps.datastore.objectify;

import java.io.File;

import pl.com.qapps.datastore.Datastore;
import pl.com.qapps.datastore.GaeHelper;
import pl.com.qapps.datastore.berkeley.BerkeleyDatastore;
import pl.com.qapps.datastore.objectify.test.Person;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;

/**
 * Testing basic functionality.
 * 
 * @author Jakub Dykowski
 * 
 */
class Test2 {

	static final String DATASTORE_PATH = "./datastore_test";
	static {
		File datastore = new File("./datastore_test");
		if (!datastore.exists())
			datastore.mkdirs();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		GaeHelper.registerEnvironment();
		Datastore datastore = BerkeleyDatastore.newLocal(DATASTORE_PATH);
		OfyService.init(datastore);

		OfyService.register(Person.class);

		Objectify ofy = OfyService.begin();

		Person person = new Person();
		person.name = "Kuba";
		person.age = 20;
		person.email = "jakub.dykowski@gmail.com";

//		Key<Person> key = Key.create(Person.class, 7L);
		Key<Person> key = ofy.put(person);
		System.out.println(ofy.get(key));
		System.out.println("id=" + key.getId());
		ofy.delete(key);
		System.out.println(ofy.get(key));
		datastore.close();
	}

}
